package com.xiaomi.controller;

import com.alibaba.fastjson.JSON;
import com.xiaomi.model.Result;
import com.xiaomi.service.OrderSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @ClassName OrderContyoller
 * @Description TODO
 * @Author WL
 * @Date 2021/11/28 21:11
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/order", produces = "application/json;charset = utf-8")
public class OrderController {
    @Autowired
    private OrderSevice orderSevice;
    /* @GetMapping("/list.do")
     @ResponseBody
     public String listSearch(@RequestParam(required = false) String name,
                              @RequestParam(required = false) Integer page,
                              @RequestParam(required = false) Integer limit) throws Exception {
         Integer startRow = (page - 1) * limit;
         List<Order> lists = orderSevice.selectType(name, startRow, limit);
         Integer count = orderSevice.getCount(name);
         Result result = new Result();
         result.setCode(0);
         result.setCount(count);
         result.setData(lists);
         result.setMsg("成功");
         String json = JSON.toJSONString(result);
         return json;

     }*/
    @PostMapping("/insert.do")
    @ResponseBody
    public String insert(@RequestParam String name,
                         @RequestParam String iamg,
                         @RequestParam Integer quantity,
                         @RequestParam String guige,
                         @RequestParam BigDecimal price,
                         @RequestParam String purchase,
                         @RequestParam String address,
                         @RequestParam Integer sku_id) throws Exception {
        orderSevice.insert(name, iamg, quantity, guige, price, purchase, address, sku_id);
        Result result = new Result();
        result.setCode(0);
        result.setMsg("成功");
        String json = JSON.toJSONString(result);
        return json;

    }
    @GetMapping("/delete.do")
    @ResponseBody
    public String delete(@RequestParam Integer id)throws Exception{
        orderSevice.delete(id);
        Result result = new Result();
        result.setCode(0);
        result.setMsg("成功");
        String json = JSON.toJSONString(result);
        return json;
    }
}
